package wxshop.service.admin.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wxshop.api.admin.dao.GoodsDao;
import wxshop.api.admin.exception.OperationFail;
import wxshop.api.admin.model.FormResult;
import wxshop.api.admin.model.GoodsInfo;
import wxshop.api.admin.service.GoodsManageService;

import java.util.List;

/**
 * Created by 121874694@qq.com on 2018/3/2.
 */
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Service
public class GoodsManageServiceImpl implements GoodsManageService {
	@Autowired
	private GoodsDao goodsDao;
	public FormResult insertGoodsInfo (GoodsInfo goodsInfo) {
		if (goodsDao.insertGoodsInfo(goodsInfo)!=1){
			throw new OperationFail();
		}
		return new FormResult(true,"添加商品信息成功！");
	}
	
	@Override
	public FormResult selectGoodsInfo () {
		List<GoodsInfo> a = goodsDao.selectGoodsInfo();
		if(a.isEmpty()){
			return new FormResult(true,"暂无商品信息！");
		}
		return new FormResult(true,a);
	}
	
	@Override
	public FormResult updateGoodsInfo (GoodsInfo goodsInfo) {
		if(goodsDao.updateGoodsInforderByid(goodsInfo)!=1){
			throw new OperationFail();
		}
		return new FormResult(true,"修改成功！");
	}
	
	@Override
	public FormResult deleteGoodsinforderByid (GoodsInfo goodsInfo) {
		if(goodsDao.deleteGoodsInfoById(goodsInfo)!=1){
			throw new OperationFail();
		}
		return new FormResult(true,"删除成功！");
	}
}
